package com.tjc.spring.mvc;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.logging.Logger;

/**
 * 功能：接收请求，响应结果，相当于转发器，中央处理器
 * 1. 扫描@Controller,@Service标注的类，实例化bean（单一职责）不过为了简单
 * 2. 匹配路由和方法
 */
public class DispatcherServlet extends HttpServlet {
    Logger log = Logger.getLogger(this.getClass().getName());


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        log.info("get service.");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
        log.info("post service.");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        log.info("dispatcherServlet init.");
        log.info(config.getInitParameter("contextConfigLocation"));
    }

}